package com.dormitory.javadormitory.common;

public enum ResultEnum {
    SUCCESS(200, "成功"),
    ERROR(1, "失败"),
    UNAUTHORIZED(401, "未授权"),
    FORBIDDEN(403, "禁止访问"),
    NOT_FOUND(404, "未找到"),
    INTERNAL_SERVER_ERROR(500, "服务器内部错误");

    private Integer code;
    private String message;

    ResultEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    // 根据code返回对应的message
    public static String getMessageByCode(Integer code) {
        for (ResultEnum element : ResultEnum.values()) {
            if (element.getCode().equals(code)) {
                return element.getMessage();
            }
        }
        return null; // 如果没有找到对应的code，返回null
    }

    // 根据message返回对应的code
    public static Integer getCodeByMessage(String message) {
        for (ResultEnum element : ResultEnum.values()) {
            if (element.getMessage().equals(message)) {
                return element.getCode();
            }
        }
        return null; // 如果没有找到对应的message，返回null
    }
}